const BaseHandler     = require('../base-handler');
const HTTP_VERBS      = require('../../../constants').HTTP_VERBS;

class PartnersHandler extends BaseHandler {

    get pattern() {
        return "/partners/:partner_id/tv_app_versions";
    }

    doGET(request, response) {
        var count = request.query.count || 5;
        var pageIndex = request.query.pageIndex || 1;
        var partnerId = request.params.partner_id;

        this.Controller.getPartnerTVAppVersions({
            partnerId: partnerId,
            pageIndex: pageIndex,
            count: count
        }, (result) => {
            response.json(result);
        });
    }

    doPOST(request, response) {
        request.body.partner_id = request.params.partner_id;

        this.Controller.createNewTVAppVersion(request.body, (result) => {
            response.json(result);
        });
    }

    setup() {
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
        this.registerVerb(HTTP_VERBS.POST, this.doPOST);
    }
}

module.exports = PartnersHandler;